﻿#region using
using System;
using Microsoft.Xna.Framework;
#endregion

namespace AwesomeTanks.Sources.GameElements.ShootElements
{
    /// <summary>
    /// Represents a weapon of the tank. Abstract class, cause the weapon have to be defined in a subclass. 
    /// </summary>
    public abstract class Weapon
    {
        #region Fields
        public int Damages { get; set; }
        public double ReloadTimer { get; set; }
        public float SpeedFactor { get; set; }
        public double CurrentReloadTimer { get; set; }
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="Weapon"/> class.
        /// </summary>
        /// <param name="reloadTimer">The duration of the reloading phase.</param>
        /// <param name="speedFactor">The speed factor of the shot.</param>
        /// <param name="damages">The base damages of a shot.</param>
        public Weapon(double reloadTimer, float speedFactor, int damages)
        {
            this.Damages = damages;
            this.ReloadTimer = reloadTimer;
            this.SpeedFactor = speedFactor;
            this.CurrentReloadTimer = 0;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Determines whether the weapon can shoot.
        /// </summary>
        /// <returns></returns>
        public Boolean CanShoot()
        {
            Boolean canShoot = false;

            if (CurrentReloadTimer >= ReloadTimer)
            {
                CurrentReloadTimer = 0;
                canShoot = true;
            }

            return canShoot;
        }

        /// <summary>
        /// Fires with the weapon.
        /// </summary>
        /// <param name="position">The initial position of the shot.</param>
        /// <param name="direction">The direction of the shot.</param>
        /// <param name="shooter">The shooter.</param>
        public abstract void Fire(Vector2 position, Vector2 direction, Player shooter);

        #endregion

        #region Update and Draw
        /// <summary>
        /// Updates the weapon with specified game time (useful to reloading).
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(GameTime gameTime)
        {
            this.CurrentReloadTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
        }
        #endregion
    }
}
